﻿using UnityEngine;
using UnityEditor;

public class BuildAssetBundlesBuildMapExample : MonoBehaviour
{
	[MenuItem("Tool/Build A AssetBundle")]
	static void BuildMapABs()
	{
		//得到用户的选择的资源
		if (Selection.assetGUIDs.Length == 0) return;

		Debug.Log (Selection.assetGUIDs.Length);

		AssetBundleBuild[] buildMap = new AssetBundleBuild[Selection.assetGUIDs.Length];

		for (int i = 0; i < Selection.assetGUIDs.Length; ++i) {
			string assetBundleName = Selection.assetGUIDs[i];
			buildMap[i].assetBundleName = assetBundleName;

			string[] enemyAssets = new string[1];
			enemyAssets[0] = assetBundleName;

			string guid = Selection.assetGUIDs [i];
			buildMap [i].assetNames = enemyAssets;
		}

		BuildPipeline.BuildAssetBundles("Assets/ABs", buildMap, BuildAssetBundleOptions.None, BuildTarget.StandaloneOSXUniversal);
	}

	[MenuItem("Tool/Show AssetDatabase bundles")]
	static void ShowAssetDatabase()
	{
		string[] bundles = AssetDatabase.GetAllAssetBundleNames ();

		for (int i = 0; i < bundles.Length; ++i) {
			Debug.Log (bundles[i]);
		}
	}
}